package wizard;



import javax.microedition.midlet.*;
import javax.microedition.pim.Contact;
import javax.microedition.pim.ContactList;
import javax.microedition.pim.PIM;
import javax.microedition.pim.PIMException;
import javax.microedition.lcdui.*;
/**
 * Wizard design pattern.
 * An example midlet that uses wizard pattern.
 *
 * @author Ben Hui
 */
public class Wizardlet extends MIDlet
{
  static Wizardlet instance;

  public Contact ct;
  public ContactList contList ;
  
  WizardEngine engine;

  public static String answer1;
  public static String answer2;


  public Wizardlet()
  {
    instance = this;
  }


  public void startApp()
  {
    // create an wizard engine
    engine = new WizardEngine( Display.getDisplay( this ) );

    // add 4 wizard dialogs to the engine
    
    engine.addDialog ( new WPage2() );
    engine.addDialog ( new WPage3() );
    engine.addDialog ( new WPage4() );
    engine.addDialog( new WPage1() );

    // start the wizard
    engine.startWizard();
  
    PIM pimInst = PIM.getInstance();
    try {
		contList = (ContactList) pimInst.openPIMList(PIM.CONTACT_LIST,PIM.READ_WRITE);
		ct = contList.createContact();
    } catch (PIMException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
    
  
  }
  
  

  /** Handle pausing the MIDlet */
  public void pauseApp() {
  }

  /** Handle destroying the MIDlet */
  public void destroyApp(boolean unconditional) {
  }

  /** Quit the MIDlet */
  public static void quitApp() {
    instance.destroyApp(true);
    instance.notifyDestroyed();
    instance = null;
  }

  public void grabaContacto(){
	  try {
	      
	      
	      
	     /*
	      addr[Contact.ADDR_LOCALITY] = "city";
	      addr[Contact.ADDR_COUNTRY] = "country";
	      addr[Contact.ADDR_POSTALCODE] = "street";
	      
	      ct.addStringArray(Contact.ADDR, Contact.ATTR_NONE, addr);
	      */
	      ct.commit();

	      if (contList != null)
	        contList.close();
	      contList = null;

	    } catch (Exception ex) {

	      return;
	    }
  }
  
  
}

